API Documentation
Public Member Functions | List of all members
nkMemory::LinearPager< T, U > Class Template Referencefinal

A pager using a linear allocation algorithm. More...

Public Member Functions

 LinearPager (size_t pageSize)
 
 ~LinearPager ()=default
 
size_t getPageSize () const
 
size_t getCurrentOffset () const
 
size_t getAllocatedPageCount () const
 
size_t getAvailablePageCount () const
 
allocate (size_t size, size_t alignment=1)
 
void reset ()
 
size_t getCurrentPageFreeMemory () const
 

Detailed Description

template<typename T = char*, typename U = DefaultMemorySpace>
class nkMemory::LinearPager< T, U >

A pager using a linear allocation algorithm.

A linear pager will allocate sequentially in the active page. When the page is full, a new page is allocated. Resetting the pager resets all allocations. This kind of pager can be useful in scenarios where allocations are used for a purpose and can be fred right after.
For instance, in a 3d renderer, it can be used to page resources used on a per frame basis (allocate for the frame, reset, reuse allocations for next frame).

Constructor & Destructor Documentation

◆ LinearPager()

template<typename T = char*, typename U = DefaultMemorySpace>
nkMemory::LinearPager< T, U >::LinearPager ( size_t  pageSize)

Constructor.

Parameters
pageSizeThe size wanted for pages within the pager.

◆ ~LinearPager()

template<typename T = char*, typename U = DefaultMemorySpace>
nkMemory::LinearPager< T, U >::~LinearPager ( )
default

Destructor.

Member Function Documentation

◆ getPageSize()

template<typename T = char*, typename U = DefaultMemorySpace>
size_t nkMemory::LinearPager< T, U >::getPageSize ( ) const
Returns
The page size used in the pager.

◆ getCurrentOffset()

template<typename T = char*, typename U = DefaultMemorySpace>
size_t nkMemory::LinearPager< T, U >::getCurrentOffset ( ) const
Returns
The current offset within the active page.

◆ getAllocatedPageCount()

template<typename T = char*, typename U = DefaultMemorySpace>
size_t nkMemory::LinearPager< T, U >::getAllocatedPageCount ( ) const
Returns
The number of pages currently allocated.

◆ getAvailablePageCount()

template<typename T = char*, typename U = DefaultMemorySpace>
size_t nkMemory::LinearPager< T, U >::getAvailablePageCount ( ) const
Returns
The number of pages still available.

◆ allocate()

template<typename T = char*, typename U = DefaultMemorySpace>
T nkMemory::LinearPager< T, U >::allocate ( size_t  size,
size_t  alignment = 1 
)

Requests an allocation.

Parameters
sizeThe size needed for the allocation.
alignmentThe alignment needed for the allocation.
Returns
An allocation fitting the conditions given, if possible. If not, it will return a default constructed object.
Remarks
Typically, a failure in allocating an object is due to the page size being too small.

◆ reset()

template<typename T = char*, typename U = DefaultMemorySpace>
void nkMemory::LinearPager< T, U >::reset ( )

Resets the status of the pager. This will make the pager reset its current tracking within the pages. Note that no memory will be freed. The point is to make already allocated memory usable again.

◆ getCurrentPageFreeMemory()

template<typename T = char*, typename U = DefaultMemorySpace>
size_t nkMemory::LinearPager< T, U >::getCurrentPageFreeMemory ( ) const
Returns
The remaining available size within active page.

The documentation for this class was generated from the following file: